function FeedExp(){
	
	var self = Ti.UI.createWindow({
		layout:"vertical",
		backgroundColor:'#ffffff'
	});
	
	
	var mainView = Ti.UI.createScrollView({
		layout:'vertical'
	});
	
	/*
	var fb = require('facebook');
	fb.appid = "1394200310814428";
	fb.permissions =  ['publish_stream'];
	fb.authorize();
	fb.addEventListener('login', function(e) {
	    if (e.success) {
	        alert('Logged in');
	    }
	});
	fb.addEventListener('logout', function(e) {
	    alert('Logged out');
	});
	
	
	mainView.add(fb.createLoginButton({
	    top : 50,
	    style : fb.BUTTON_STYLE_WIDE
	}));
	*/
	var xhr = Titanium.Network.createHTTPClient();
	xhr.onload = function() {
		var TokenResponse = this.responseText;
		var TokenArray = TokenResponse.split("=");
		var Token = TokenArray[1];
	   	if (Token !="")
	   	{
	   		getFeeds(Token);
	   	}  
	};
 
	xhr.open("GET","https://graph.facebook.com/oauth/access_token?client_id=1394200310814428&client_secret=9408a030f2b9ae3f35534ff71dcb26ca&grant_type=client_credentials");
	xhr.send();
 
function getFeeds(Token)
{
	
	var fb = require('facebook');
	fb.appid = "1394200310814428";
	fb.requestWithGraphPath('https://www.facebook.com/AbeoElectra/feed', {access_token: Token}, 'GET', function(e){
    	//alert(resultText);
        if (e.success) {
        
            alert("Success!  From FB: " + e.result);
            var resultText = e.result;
            var s = JSON.parse(resultText);
            var data = [];
 
            var header = Ti.UI.createTableViewRow({
                        height: 30,
                        title: "Feeds: " + s.data.length
 
            });
            data.push(header);
            for (var c=0;c<s.data.length;c++) 
            {
                   var row = Ti.UI.createTableViewRow({
                        height: 30,
                        title: s.data[c].message
 
                   });
 
                    data.push(row);
            }
 
            var tableview = Titanium.UI.createTableView();
            tableview.setData(data);
            mainView.add(tableview);
            mainView.add(fb);
        } else {
            if (e.error) {
                alert(e.error);
            } else {
                alert("Unkown result");
            }
        }
    });
 /*
	
	
	
    Ti.Facebook.requestWithGraphPath('https://www.facebook.com/AbeoElectra/feed', {access_token: Token}, 'GET', function(e){
    	alert(resultText);
        if (e.success) {
            alert("Success!  From FB: " + e.result);
            var resultText = e.result;
            var s = JSON.parse(resultText);
            var data = [];
 
            var header = Ti.UI.createTableViewRow({
                        height: 30,
                        title: "Feeds: " + s.data.length
 
            });
            data.push(header);
            for (var c=0;c<s.data.length;c++) 
            {
                   var row = Ti.UI.createTableViewRow({
                        height: 30,
                        title: s.data[c].message
 
                   });
 
                    data.push(row);
            }
 
            var tableview = Titanium.UI.createTableView();
            tableview.setData(data);
            mainView.add(tableview);
        } else {
            if (e.error) {
                alert(e.error);
            } else {
                alert("Unkown result");
            }
        }
    });*/
 
}
	
	//https://www.facebook.com/AbeoElectra
//App ID:	1394200310814428
//App Secret:	9408a030f2b9ae3f35534ff71dcb26ca
	self.add(mainView);
		
	return self;
}
module.exports = FeedExp;
